import { saveAs } from 'file-saver';
import { useEffect } from 'react';
import { request } from 'umi';
export default () => {
  function getStream() {
    request('images/UpLoads/AppBundle/83a47b3c1aaf4c6f9bff327c2442cf84.pdf', {
      // request('http://localhost:8001/images/UpLoads/AppBundle/c15c671254ce455f9a10f1af5cac37cd.docx', {
      method: 'get',
      responseType: 'blob', //
    }).then((res) => {
      const blob = new Blob([res], {
        type: 'application/pdf',
      });
      const url = URL.createObjectURL(blob);
      console.log(22222222222, blob, res);

      const iframe = document.getElementById('iframe') as HTMLFormElement;
      iframe.src = url;
      // 可解决隐藏操作栏
      // document.getElementById('iframe').src = url + '#toolbar=0';
      saveAs(blob, 'xxx.pdf');
    });
  }

  useEffect(() => {
    // getStream();
  }, []);
  return (
    <>
      <div onClick={getStream}>sssss</div>
      <iframe src="" id="iframe" frameBorder="0"
              style={{ width: '100%', height: '100vh' }}
      />
    </>

  );
};
